# /usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2022/1/11 14:25
# @Author  : lt
# @Email   : lt@163.com
# @File    : add_kehuguanhuai_page.py
# @Software: PyCharm

from selenium.webdriver.common.by import By
from page.KHGL_page.Base_Page import BasePage
from selenium.webdriver.support.select import Select
class Add_Guanhuai_Page(BasePage):
    '''添加客户关怀界面'''
    # 定位新建关怀按钮
    add_guanhuai_locator = (By.CSS_SELECTOR, 'body > div.container > div.row > div:nth-child(1) > div > a > i')
    # 定位客户输入框
    kehu_shuru_locator = (By.ID, 'customer_name')
    # 定位客户表
    tobdy_locator = (By.ID, 'datas')
    # 定位确认按钮
    queren_locator = (By.XPATH, '/html/body/div[8]/div[3]/div/button[1]/span')
    # 定位关怀主题
    guanhuai_zhuti_locator = (By.ID, 'name')
    # 定位关怀日期
    guanhuai_time_locator = (By.ID, 'care_time')
    # 定位执行人输入框
    fuzeren_locator = (By.ID, 'owner_name')
    # 定位执行人表
    tobdy_fuzeren_locator = (By.ID, 'd_content')
    # 定位执行人勾选确定按钮
    queren_fuzeren_locator = (By.XPATH, '/html/body/div[7]/div[3]/div/button[1]/span')

    # 定位关怀类型下拉框
    guanhuai_leixing_locator = (By.CSS_SELECTOR,
                                'body > div.container > div.row > div > form > table > tbody > tr:nth-child(4) > td:nth-child(4) > select')
    # 定位关怀内容输入框
    guanhuai_neirong_locator = (By.CSS_SELECTOR,
                                'body > div.container > div.row > div > form > table > tbody > tr:nth-child(5) > td:nth-child(2) > textarea')
    # 定位备注输入框
    description_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tbody/tr[6]/td[2]/textarea')
    # 定位保存按钮
    baocun_locator = (By.NAME, 'submit')
    # 定位添加成功
    add_succeful_locator = (By.CSS_SELECTOR, 'body > div.container > div.alert.alert-success')

    # 点击客户输入框
    def kehu_click(self):
        self.driver.find_element(*self.kehu_shuru_locator).click()
    # 选择客户
    def kehu_tobdy(self, kehu):
        tobdy_kehu = self.driver.find_element(*self.tobdy_locator)
        trs = tobdy_kehu.find_elements(By.TAG_NAME, 'tr')
        for i in trs:
            tds = i.find_elements(By.TAG_NAME, 'td')
            if tds[1].text == kehu:
                tds[0].find_element(By.CSS_SELECTOR, '[name="customer"]').click()
    # 点击确认按钮
    def queren_click(self):
        self.driver.find_element(*self.queren_locator).click()
    # 输入关怀主题
    def guanhuaizhuti(self,zhuti):
        self.driver.find_element(*self.guanhuai_zhuti_locator).send_keys(zhuti)
    # 输入关怀日期
    def guanhuai_time_shuru(self,guanhuai_time):
        self.driver.find_element(*self.guanhuai_time_locator).send_keys(guanhuai_time)
    # 点击执行人输入框
    def zhixingren_click(self):
        self.driver.find_element(*self.fuzeren_locator).click()
    # 选择要输入的负责人
    def zhixingren_name(self,zhixingren):
        tobdy_fuzeren = self.driver.find_element(*self.tobdy_fuzeren_locator)
        trs2 = tobdy_fuzeren.find_elements(By.TAG_NAME, 'tr')
        for e in trs2:
            tds2 = e.find_elements(By.TAG_NAME, 'td')
            if tds2[1].text == zhixingren:
                # 点击负责人
                tds2[0].click()
    # 点击确定
    def queren_ok_click(self):
        self.driver.find_element(*self.queren_fuzeren_locator).click()
    # 输入关怀类型
    def guanhuai_leixing(self,leixing):
        Select(self.driver.find_element(*self.guanhuai_leixing_locator)).select_by_visible_text(leixing)
    # 输入关怀内容
    def guanhua_neirong(self,guanhuai_neirong):
        self.driver.find_element(*self.guanhuai_neirong_locator).send_keys(guanhuai_neirong)
    # 输入备注
    def beizhu_shuru(self,description):
        self.driver.find_element(*self.description_locator).send_keys(description)
    # 点击保存
    def baocun_button(self):
        self.driver.find_element(*self.baocun_locator).click()
    # 断言
    def tianjia_succeful(self):
        text = self.driver.find_element(*self.add_succeful_locator).text
        return text